﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <title>收入管理</title>
    <script type="text/javascript">
        var errorMsg = "操作失败！";
        var successMsg = "操作成功！";

        //添加按钮事件
        function addContent(type) {
            var request = $.ajax({
                url: "../Revenue/ShowAddWindow",
                data: { type: type },
                type: "POST", dataType: "html"
            });
            request.done(function (msg) {
                $("#Window").data("tWindow").center().open();
                $("#tContent").html(msg);
            });
            request.fail(function (jqXHR, textStatus) {
                alert("Request failed: " + textStatus);
            });
        }

        //ShowAddWindow.ascx 中提交按钮的事件
        function insertContent() {
            var request = $.ajax({
                url: "../Revenue/InsertBudgetApplyTable",
                data: $("#tContent form").serializeArray(),
                type: "POST", dataType: "text"

            });
            request.done(function (msg) {
                if (msg == "success") {
                    alert(successMsg);
                    $("#Window").data("tWindow").close();
                    $("#Budget").data("tGrid").rebind();
                    $("#Actual").data("tGrid").rebind();
                    $("#tContent").html("");
                }
                else {
                    alert(errorMsg);
                }
            });
            request.fail(function (jqXHR, textStatus) {
                alert("Request failed: " + textStatus);
            });
        }

        //修改按钮事件
        function editContent(applyId, type) {
            var request = $.ajax({
                url: "../Revenue/ShowEditWindow",
                data: { applyId: applyId, type: type },
                type: "POST", dataType: "html"
            });
            request.done(function (msg) {
                $("#Window").data("tWindow").center().open();
                $("#tContent").html(msg);
            });
            request.fail(function (jqXHR, textStatus) {
                alert("Request failed: " + textStatus);
            });
        }

        //ShowEditWindow.ascx 中取消按钮的事件
        function closeWindow() {
            $("#Window").data("tWindow").close();
            $("#tContent").html("");
        }

        //ShowEditWindow.ascx 中更新按钮的事件
        function saveContent() {
            var request = $.ajax({
                url: "../Revenue/SaveBudgetApplyTable",
                data: $("#tContent form").serializeArray(),
                type: "POST", dataType: "text"

            });
            request.done(function (msg) {
                if (msg == "success") {
                    alert(successMsg);
                    $("#Window").data("tWindow").close();
                    $("#Budget").data("tGrid").rebind();
                    $("#Actual").data("tGrid").rebind();
                    $("#tContent").html("");
                }
                else {
                    alert(errorMsg);
                }
            });
            request.fail(function (jqXHR, textStatus) {
                alert("Request failed: " + textStatus);
            });

        }

        //删除按钮事件
        function deleteContent(applyId) {
            var request = $.ajax({
                url: "../Revenue/DeleteBudgetApplyTable",
                data: { applyId: applyId},
                type: "POST", dataType: "text"

            });
            request.done(function (msg) {
                if (msg == "success") {
                    alert(successMsg);
                    $('#Budget').data('tGrid').rebind();
                    $("#Actual").data("tGrid").rebind();
                }
                else {
                    alert(errorMsg);
                }

            });
            request.fail(function (jqXHR, textStatus) {
                alert("Request failed: " + textStatus);
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        收入管理</h2>
    <h3>
        单位名称：<%= ViewBag.DepName %></h3>
    <%--用于加载收入预算明细信息的Window--%>
    <% Html.Telerik().Window()
                .Name("Window")
                .Title("收入明细信息")
                .Draggable(true)
                .Resizable(resizing => resizing
                    .Enabled(true)
                    )
                    .Scrollable(true)
                    .Modal(true)
                    .Buttons(b => b.Close())
                    .Content(() =>
                    {
    %>
    <div id="tContent">
    </div>
    <%
                    }
                  )
                 .Width(370)
                 .Height(850)
                 .Visible(false)
                 .Render();   
    %>
    <h3>
        <%= ViewBag.RevenueYear %>年收入预算情况</h3>
    <%= Html.Telerik().Grid<FinancialManagement.Models.BudgetApplyTable>()        
    .Name("Budget")
    .ToolBar(toolbar => toolbar.Template("<input type='button' id='btnAdd' value='添加' onclick='addContent(1)'/>"))
    .Columns(columns =>        
    {            
        columns.Bound(o => o.ApplyID);            
        columns.Bound(o => o.ApplyDepartment);
        columns.Bound(o => o.ApplyDepartmentName);
        columns.Bound(o => o.RevenueTypeCode);
        columns.Bound(o => o.RevenueTypeName);
        columns.Bound(o => o.ChargeProjectName);
        columns.Bound(o => o.CalculateUnitCode);
        columns.Bound(o => o.CalculateUnitName);
        columns.Bound(o => o.ChargeScopeCode);
        columns.Bound(o => o.ChargeStandard);
        columns.Bound(o => o.ChargeScopeName);
        columns.Bound(o => o.BudgetTotalRreven);
        columns.Bound(o => o.BudgetAccding);
        columns.Bound(c => c.Illustration).ClientTemplate("<a href='<#= Illustration #>'>下载</a>").Width(200);
        columns.Bound(o => o.Notes);
        columns.Bound(o => o.Notes).ClientTemplate("<input type='button' id='btnEdit' value='修改' onclick='editContent(<#= ApplyID #>,1)'/>" +
            "<input type='button' id='btnDelete' value='删除' onclick='deleteContent(<#= ApplyID #>)'/>").Title("操作");         
          
    })        
    .DataBinding(dataBinding => dataBinding.Ajax().Select("BindingBudgetRevenue", "Revenue"))        
    .Pageable()        
    .Sortable()        
    .Scrollable()              
    .Filterable()%>
    <h3>
        <%= ViewBag.BudgetYear %>年实际收入情况</h3>
    <%= Html.Telerik().Grid<FinancialManagement.Models.BudgetApplyTable>()        
    .Name("Actual")
    .ToolBar(toolbar => toolbar.Template("<input type='button' id='btnAdd' value='添加' onclick='addContent(2)'/>"))
    .Columns(columns =>        
    {            
        columns.Bound(o => o.ApplyID);            
        columns.Bound(o => o.ApplyDepartment);
        columns.Bound(o => o.ApplyDepartmentName);
        columns.Bound(o => o.RevenueTypeCode);
        columns.Bound(o => o.RevenueTypeName);
        columns.Bound(o => o.ChargeProjectName);
        columns.Bound(o => o.CalculateUnitCode);
        columns.Bound(o => o.CalculateUnitName);
        columns.Bound(o => o.ChargeScopeCode);
        columns.Bound(o => o.ChargeStandard);            
        columns.Bound(o => o.ChargeScopeName);
        columns.Bound(o => o.ActualTotalRreven);
        columns.Bound(c => c.Illustration).ClientTemplate("<a href='<#= Illustration #>'>下载</a>").Width(200);
        columns.Bound(o => o.Notes);
        columns.Bound(o => o.Notes).ClientTemplate("<input type='button' id='btnEdit' value='修改' onclick='editContent(<#= ApplyID #>,2)'/>" +
            "<input type='button' id='btnDelete' value='删除' onclick='deleteContent(<#= ApplyID #>)'/>").Title("操作");         
          
    })
    .DataBinding(dataBinding => dataBinding.Ajax().Select("BindingActualRevenue", "Revenue"))        
    .Pageable()        
    .Sortable()        
    .Scrollable()              
    .Filterable()%>
</asp:Content>
